package javabase.schoolwork.day6_15;


import java.lang.reflect.Field;

/**
 * @author fance
 * @date 2018/6/14 21:47
 */
interface China{
     static String NATION = "china";
     static String AUTHOR = "fance";
    void sayChina();
    String sayHello(String name,int age);
}
public class Person implements China{

    private String name;
    private int age;


    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public void sayChina() {
        System.out.println(AUTHOR + ": " + NATION);
    }

    @Override
    public String sayHello(String name, int age) {
        return name + ": " + age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchFieldException {
        Class<?> c = Class.forName("javabase.schoolwork.day6_15.Person");

            Person p = (Person) c.newInstance();
//         Field[] fields = person.getDeclaredFields();
//         Field[] fields = person.getFields();
       /*  fields[0].setAccessible(true);
         fields[0].set(p,"fance");
         fields[1].setAccessible(true);
         fields[1].set(p,20);
        for (Field field : fields) {
            System.out.print(field.get(p));
        }*/

     /*   for (int i = 0; i < fields.length; i++) {
            Class r = fields[i].getType();
            System.out.println(Modifier.toString(fields[i].getModifiers()));
            System.out.println(r.getName());
            System.out.println(fields[i].getName());

            System.out.println();
            System.out.println();
        }
*/


        Field nameField = c.getDeclaredField("name");
        Field ageField = c.getDeclaredField("age");

      //  nameField.setAccessible(true);
        nameField.set(p,"fance");
      //  ageField.setAccessible(true);
        ageField.set(p,20);

        System.out.println(nameField.get(p));
        System.out.println(ageField.get(p));
    }
}
